package com.weiguan.xmpp;

import java.net.HttpURLConnection;
import java.net.URL;

public class Config {
	public static final String PRO_XMPP_URL = "xmpp.weilive.cc";// 生产
	public static final String TEST_XMPP_URL = "120.131.9.35";// 测试

	public static final String PRO_AUTH = "wdlanKhy6l1FvTJj";// 生产
	public static final String TEST_AUTH = "KLUe2oMl667baF2y";// 测试

	public static final String TEST_SERVICE_NAME = "weilive.tv";// 测试

	public static final int ROOM_ID = 1043481;
	public static EnvType envType = EnvType.PRODUCE;// 0:测试,1:正式

	public static String getServiceName() {
		if (envType == EnvType.TEST) {
			return TEST_SERVICE_NAME;
		}
		return PRO_XMPP_URL;

	}

	public static String getHost() {
		if (envType == EnvType.TEST) {
			return TEST_XMPP_URL;
		}
		return PRO_XMPP_URL;

	}

	public static String getXmppURL() {
		if (envType == EnvType.TEST) {
			return TEST_XMPP_URL;
		}
		return PRO_XMPP_URL;
	}

	public static String getXmppAuth() {
		if (envType == EnvType.TEST) {
			return TEST_AUTH;
		}
		return PRO_AUTH;
	}

	public static int HttpGoReturnStatus(String goURL, String method, String body) {
		HttpURLConnection urlConnection = null;
		try {
			urlConnection = (HttpURLConnection) new URL(goURL).openConnection();
			urlConnection.setRequestMethod(method);
			urlConnection.setDoOutput(true);
			urlConnection.setDoInput(true);
			urlConnection.setUseCaches(false);
			urlConnection.setConnectTimeout(6000);
			urlConnection.setReadTimeout(6000);
			// 正式
			urlConnection.setRequestProperty("Authorization", Config.getXmppAuth());
			urlConnection.setRequestProperty("Content-Type", "application/json");
			if (body != null) {
				urlConnection.getOutputStream().write(body.getBytes());
				urlConnection.getOutputStream().flush();
				urlConnection.getOutputStream().close();
			}
			return urlConnection.getResponseCode();

		} catch (Exception e) {
			return -1;
		} finally {
			urlConnection.disconnect();
		}
	}
}
